Add BrowserStack SDK + Playwright behave sample#1
Conversation
Provides customers with a working starting point for running behave tests on BrowserStack via Playwright Python and the BrowserStack Python SDK. Mirrors the shape of browserstack/cucumber-ruby-browserstack (browserstack-sdk-selenium-4 branch) but adapted for behave + Playwright: - One browserstack.yml at root declares 3 platforms covering all 3 Playwright browser engines (chromium / firefox / webkit). The SDK monkeypatches Playwright launches and routes to the per-platform browser, so customer code uses chromium.launch() unchanged across all three. - Alternate configs under config/ for single-platform and BrowserStack Local modes; Makefile swaps them in around the SDK call and restores the parallel default afterwards (even on failure). - Local mode self-tests: serves a small static page on :45454 from features/local-html/ and routes a localhost scenario through the BS Local tunnel that the SDK starts/stops automatically. - GitHub Actions workflow uses workflow_dispatch + commit_sha + check-status reporting, mirroring the cucumber-java-playwright-browserstack pattern. - Playwright pinned to ==1.49.0 because PW >=1.50 trips an SDK monkeypatch arg that no longer matches (`unexpected keyword argument 'artifactsDir'`). Verified end-to-end against BrowserStack: - make parallel: 3 sessions (chrome/pw-firefox/pw-webkit), all passed - make single: 1 chrome session, passed - make local: 1 session via Local tunnel against localhost:45454, passed Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| # the launch keyword args in a way the current SDK doesn't yet handle | ||
| # (`unexpected keyword argument 'artifactsDir'`). Keep at 1.49.0 until the | ||
| # SDK release notes call out a higher upper bound. | ||
| playwright==1.49.0 |
There was a problem hiding this comment.
Why it is not latest and pointed to specific version?
There was a problem hiding this comment.
There seems to be an issue in SDK for PW > 1.50.
Ticket raised here https://browserstack.atlassian.net/browse/SDK-5954
|
Thanks for the review @karanshah-browserstack — pushed Re:
|
| consoleLogs: errors | ||
|
|
||
| # Identifier so BrowserStack can tag the sample source — please leave as-is. | ||
| source: behave-playwright-sdk:sample-master:v1.0 |
There was a problem hiding this comment.
behave-playwright-browserstack
There was a problem hiding this comment.
Fixed in fa69904 — was behave-playwright-sdk:sample-master:v1.0 (my made-up -sdk prefix). Updated to behave-playwright:sample-master:v1.0 matching the existing convention: cucumber-ruby uses cucumber-ruby:sample-master:v1.1, cucumber-java-playwright uses cucumber-java-playwright:sample-master:v1.0 — pattern is <framework>-<library>:sample-master:v<N>. Happy to coordinate the version with the ASI team before merge if you'd like.
Karan's review (#1, #2, #4) pushed back on the per-mode config files and the Makefile-as-profile-switcher. Aligning with the canonical cucumber-ruby-browserstack shape (one feature run unchanged): - Drop Makefile and config/{single,local}.yml — the Python SDK reads only ./browserstack.yml so the swap was the workaround; aligning instead means one yml, one command. - Drop features/local.feature, local-html/, and local_steps.py. Customers needing the Local tunnel flip browserstackLocal: true and rerun the same command (documented in README). - Drop buildIdentifier from browserstack.yml — pure dashboard UX, not required, and Karan flagged it as noise. - CI workflow runs browserstack-sdk behave directly (no make targets). - README pruned to single-mode setup + Running + Local-toggle note.
Was `behave-playwright-sdk:...` — my made-up `-sdk` prefix that doesn't match any real convention. Other samples use `<framework>-<library>:sample-master:v<N>` (cucumber-ruby, cucumber-java-playwright), so the analog here is `behave-playwright:sample-master:v1.0`. Addresses #1 (comment)
Was `playwright==1.49.0` pinned to dodge the SDK monkeypatch's `artifactsDir` kwarg mismatch on PW >=1.50. Customers get the latest Playwright now; if the SDK still rejects the new kwarg they'll see `TypeError: ... unexpected keyword argument 'artifactsDir'` until BS ships an updated SDK. Resolves #1 (comment)
| consoleLogs: errors | ||
|
|
||
| # Identifier so BrowserStack can tag the sample source — please leave as-is. | ||
| source: behave-playwright:sample-master:v1.0 |
There was a problem hiding this comment.
behave-playwright-browserstack
There was a problem hiding this comment.
behave-playwright-browserstack:sample-main:v1.0
- requirements.txt: pin to 1.49.0 (avoid drift; matches what we test). - browserstack.yml: source -> behave-playwright-browserstack:sample-main:v1.0 to reflect the actual repo and default branch. Verified end-to-end via SDK: 3/3 sessions passed (chromium / firefox / webkit). Build: 9997a825ccaa7a0eef53e2aaf297763c0d3e7b26
| @@ -0,0 +1,59 @@ | |||
| # ============================= | |||
There was a problem hiding this comment.
Please ensure that the structure is similar to: https://github.com/browserstack/junit-browserstack/blob/master/junit-5/browserstack.yml
A couple of comments are missing.
buildIdentifier key is missing as well.
There was a problem hiding this comment.
addressed
Addresses xxshubhamxx review: match structure of junit-browserstack/junit-5/browserstack.yml, add missing comments, add buildIdentifier key.
|
@xxshubhamxx — addressed in
Restructured
Behave-specific values kept: PTAL. |
|
Verified Build: REST API (
The |
|
Hi @Jimesh-browserstack |
Mirrors the 2-sample pattern from cucumber-java-browserstack and junit-browserstack so customers get one public-site sample plus one BrowserStack Local sample. - features/local.feature — navigates http://bs-local.com:45454/ and asserts the page title contains "BrowserStack Local". - features/steps/local_steps.py — two steps. - features/local-html/index.html — title-matching page; start with `python3 -m http.server 45454 --directory features/local-html` before running the local feature. - browserstack.yml — browserstackLocal: true (matches cucumber-java-browserstack canonical so the SDK starts and stops the tunnel for every run). - README.md — repo layout updated; Running section split into "Sample test" and "Local test" subsections with explicit local-server start command. Live-verified end-to-end: build 03f2c770c3b15871829075c20f45ad4a826b56cf returns status=passed for all 6 sessions (2 scenarios x 3 Playwright engines: chromium 148, playwright-firefox 148, playwright-webkit 18.2).
|
@xxshubhamxx — added in
Mirrored the 2-sample pattern from your BDD reference (
Live verificationFresh clone of Build: REST API (
Both scenarios × 3 Playwright engines (chromium / firefox / webkit) all green. @karanshah-browserstack — flagging FYI: this re-adds PTAL. |
Summary
Customer-facing starting point for running behave tests on BrowserStack via Playwright Python and the BrowserStack Python SDK. Mirrors the shape of
browserstack/cucumber-ruby-browserstack(browserstack-sdk-selenium-4 branch) but adapted for behave + Playwright.What customers get
Three customer-facing entry points:
make parallel— runs across the three Playwright engine families (chromium / firefox / webkit) in parallel on BrowserStackmake single— one chromium platformmake local— one chromium platform + BrowserStack Local tunnel against a local HTTP server the Makefile spins up on:45454Design notes
features/environment.pycallschromium.launch()unconditionally; the SDK monkeypatches Playwright at runtime to route the launch to the per-platform browser configured inbrowserstack.yml. Nochromium.connect(wss_url)plumbing needed in customer code (this differs from the Java SDK behavior)../browserstack.yml, sosingleandlocalMake targets copy in alternates fromconfig/, run, and restore the parallel default afterwards (even on failure).make localserves a small static page onlocalhost:45454and routes a localhost-targeting scenario through the BS Local tunnel that the SDK starts/stops automatically.==1.49.0. PW>=1.50trips an SDK monkeypatch arg that no longer matches (unexpected keyword argument 'artifactsDir'). Comment inrequirements.txtexplains.cucumber-java-playwright-browserstackpattern:workflow_dispatchonly with acommit_shainput, posts check status back to that SHA. Nopush/pull_requesttriggers, so BrowserStack minutes aren't burned on every commit.Local verification (already complete)
Ran each Make target end-to-end against BrowserStack from a fresh clone with creds in env vars:
make parallelmake singlemake localCleanup checks on every run:
browserstack.ymlrestored to 3-platform default aftersingleandlocal, no leftover.bakfile, no orphanpython3 -m http.serveron:45454.CI verification (pending post-merge)
workflow_dispatchworkflows only become dispatchable from the Actions UI once they exist on the default branch — so CI can't be validated against this branch before merge. After merge, dispatch the workflow againstmainHEAD; if BrowserStack auth fails it means the org-level Actions secrets (BROWSERSTACK_USERNAME/BROWSERSTACK_ACCESS_KEY) aren't wired through to this repo and need to be added by an Actions admin (same setup ascucumber-java-playwright-browserstack).Test plan
make parallelruns all 3 platforms in parallel — see Build URL abovemake singleruns one chromium sessionmake localstarts BS Local tunnel, serves localhost page, scenario passesbrowserstack.ymlis restored aftersingle/local, no.bakleftoverpython3 -m http.serveron:45454aftermake localworkflow_dispatchruns green post-merge (pending — see "CI verification" above)🤖 Generated with Claude Code